/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import BE.Category;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author notandi
 */
public class CategoryManager
{

    private static CategoryManager instance = null;

    private List<Category> categories;

    private CategoryManager()
    {
        categories = new ArrayList<>();
    }

    public static CategoryManager getInstance()
    {
        if (instance == null)
        {
            instance = new CategoryManager();
        }
        return instance;
    }

    public Category getById(int id)
    {
        for (Category c : categories)
        {
            if (c.getId() == id)
            {
                return c;
            }
        }
        return null;
    }

    public Category getByName(String name)
    {
        for (Category c : categories)
        {
            if (c.getName().equals(name))
            {
                return c;
            }
        }
        return null;
    }

    public final List<Category> getAll()
    {
        return categories;
    }
}
